﻿using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using 基于WPF的电缆采样数据分析系统.Models.Enums;
using 基于WPF的电缆采样数据分析系统.Service;
using 基于WPF的电缆采样数据分析系统.Tools.LangugeTool;
using 基于WPF的电缆采样数据分析系统.Tools.MessagePopupTool;
using 基于WPF的电缆采样数据分析系统.ViewModels.TDRWork.OptionPage;

namespace 基于WPF的电缆采样数据分析系统.ViewModels.TDRWork
{
    public class OptionUCViewModel : BindableBase, IDialogHostAware
    {
        // 单例
        public static OptionUCViewModel Instance = new OptionUCViewModel();

        // 主机名
        private const string DialogHostName = "RootDialog";

        #region 确定
        /// <summary>
        /// 确定命令
        /// </summary>
        public DelegateCommand SaveCommand { get; set; }

        /// <summary>
        /// 确定方法
        /// </summary>
        private void SaveFun()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                // 语言是否修改
                if (!(LangugeUpdate == 2))
                {
                    // 中文
                    if (LangugeUpdate == 0)
                    {
                        MessagePopup.DisplayMessagePopup(LangugeConvertor.GetValue("LanguageChangeToChinese"));
                        LangugeUpdate = 2;
                        GlobalVariableEdit.LangugeStatus = LangugeType.Chinese;
                    }

                    // 英文
                    if (LangugeUpdate == 1)
                    {
                        MessagePopup.DisplayMessagePopup(LangugeConvertor.GetValue("LanguageChangeToEnglish"));
                        LangugeUpdate = 2;
                        GlobalVariableEdit.LangugeStatus = LangugeType.English;
                    }
                }

                // 任务默认参数被修改
                if (DefaultParamUpdate == 1)
                {
                    MessagePopup.DisplayMessagePopup(LangugeConvertor.GetValue("DefaultTaskParametersAreSuccessfullyModified"));
                    DefaultParamUpdate = 0;
                }

                DialogParameters paras = new DialogParameters();
                paras.Add("CurrentSelectedLanguge", CurrentSelectedLanguge);
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.Yes, paras));
            }

        }
        #endregion

        #region 取消
        /// <summary>
        /// 取消命令
        /// </summary>
        public DelegateCommand CancelCommand { get; set; }

        /// <summary>
        /// 取消方法
        /// </summary>
        private void CancelFun()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No));
            }
        }
        #endregion

        /// <summary>
        /// 打开过程中
        /// </summary>
        /// <param name="parameters"></param>
        public void OnDialogOpening(IDialogParameters parameters)
        {

        }

        /// <summary>
        /// 构造器
        /// </summary>
        public OptionUCViewModel()
        {
            // 绑定确定和取消命令
            SaveCommand = new DelegateCommand(SaveFun);
            CancelCommand = new DelegateCommand(CancelFun);

            
        }


        #region 语言类型

        /// <summary>
        /// 当前语言
        /// </summary>
        private LangugeType _CurrentSelectedLanguge;

        /// <summary>
        /// 当前语言
        /// </summary>
        public LangugeType CurrentSelectedLanguge
        {
            get { return _CurrentSelectedLanguge; }
            set
            {
                _CurrentSelectedLanguge = value;
                RaisePropertyChanged();
            }
        }

        #endregion


        #region 选项参数是否修改

        /// <summary>
        /// 语言 0-中文 1-英语 2-未修改
        /// </summary>
        private int _LangugeUpdate = 2;

        /// <summary>
        /// 语言 0-中文 1-英语 2-未修改
        /// </summary>
        public int LangugeUpdate
        {
            get { return _LangugeUpdate; }
            set { 
                _LangugeUpdate = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 默认参数 0-未修改 1-已修改
        /// </summary>
        private int _DefaultParamUpdate = 0;

        /// <summary>
        /// 默认参数 0-未修改 1-已修改
        /// </summary>
        public int DefaultParamUpdate
        {
            get { return _DefaultParamUpdate; }
            set { 
                _DefaultParamUpdate = value;
                RaisePropertyChanged();
            }
        }


        #endregion
    }
}
